﻿/*
* Activity Tracking Log v0.1.1 - http://activitytrackinglog.codeplex.com
* Activity Tracking Log for ASP.Net & ASP.Net MVC
* Copyright (c) 2011 Vadim Burac
* Licensed under the Microsoft Public License (Ms-PL)
* http://activitytrackinglog.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActivityTrackingLog.Configuration.ConfigSections;
using System.Configuration;

namespace ActivityTrackingLog.Configuration
{
    internal static class Config
    {
        #region private data

        private static readonly Dictionary<string, BaseConfigSection> _sections = new Dictionary<string, BaseConfigSection>(){ 
            {"log", null},
            {"storage", null},
            {"clientSideAccess", null},
            {"api", null},
            {"ui", null}
        };

        #endregion

        #region public props

        public static LogConfigSection Log
        {
            get
            {
                return _sections["log"] as LogConfigSection;
            }
        }

        public static StorageConfigSection Storage
        {
            get
            {
                return _sections["storage"] as StorageConfigSection;
            }
        }

        public static ClientAccessConfigSection ClientSideAccess
        {
            get
            {
                return _sections["clientSideAccess"] as ClientAccessConfigSection;
            }
        }

        public static ApiConfigSection Api
        {
            get
            {
                return _sections["api"] as ApiConfigSection;
            }
        }
        
        public static UiConfigSection Ui
        {
            get
            {
                return _sections["ui"] as UiConfigSection;
            }
        }

        #endregion

        #region ctors

        static Config()
        {
            _sections.Keys.ToList().ForEach(tagName =>
                _sections[tagName] = ReadConfigSection(
                    string.Concat("activityTrackingLog/", tagName)
                ));
        }

        #endregion

        #region helpers

        private static BaseConfigSection ReadConfigSection(string path)
        {
            return ConfigurationManager.GetSection(path) as BaseConfigSection;
        }

        #endregion
    }
}
